<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Escort_news_entity{
	var $current_dbprefix = "";
	var $id = 0;
	var $language_id = 0;
	var $title = '';
	var $slug = '';
	var $news = "";
	var $category_id = 0;
	var $order = 0;
	var $site_ref = '';
	var $created_time = '';
	var $status = 0;
	function __construct() {
		$ci= & get_instance();
		$this->current_dbprefix = $ci->db->dbprefix;
		$ci->db->set_dbprefix('default_');
	}
	function setId($input){
		$this->id=$input;
	}
	function setLanguageId($input){
		$this->language_id =$input;
	}
	function setTitle($input){
		$this->title =$input;
	}
	function setSlug($input){
		$this->slug =$input;
	}
	function setNews($input){
		$this->news =$input;
	}
	function setCategoryId($input){
		$this->category_id =$input;
	}
	function setOrder($input){
		$this->order =$input;
	}
	function setCreatedTime($input){
		$this->created_time =$input;
	}
	function setStatus($input){
		$this->status =$input;
	}
	function setSiteRef($input){
		$this->site_ref =$input;
	}
	
	
	function getId(){
		return $this->id;
	}
	function getLanguageId(){
		return $this->language_id;
	}
	function getTitle(){
		return $this->title;
	}
	function getSlug(){
		return $this->slug;
	}
	function getNews(){
		return $this->news;
	}
	function getCategoryId(){
		return $this->category_id;
	}
	function getOrder(){
		return $this->order;
	}
	function getCreatedTime(){
		return $this->created_time;
	}
	function getStatus(){
		return $this->status;
	}
	function getSiteRef(){
		return $this->site_ref;
	}
	
	function init($cmd, $input)
	{
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		if($cmd == 'id'){
			$result = $ci->db->where('id',$input)->get(TBL_ESCORT_NEWS)->result();
		}else if($cmd == 'slug'){
			$result = $ci->db->where('slug',$input)->get(TBL_ESCORT_NEWS)->result();
		}else if($cmd == 'language_id'){
			$result = $ci->db->where('language_id',$input)->get(TBL_ESCORT_NEWS)->result();
		}else if($cmd == 'site_ref'){
			$result = $ci->db->where('site_ref',$input)->get(TBL_ESCORT_NEWS)->result();
		}else{
			return false;
		}
		if( !empty($result) ){
			$this->id = $result[0]->id;
			$this->language_id = $result[0]->language_id;
			$this->category_id = $result[0]->category_id;
			$this->order = $result[0]->order;
			$this->title = $result[0]->title;
			$this->slug = $result[0]->slug;
			$this->news = $result[0]->news;
			$this->created_time = $result[0]->created_time;
			$this->status = $result[0]->status;
			$this->site_ref = $result[0]->site_ref;
			return $this;
		}
		return false;
	}
	function getEscortNewsList(){
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		return $ci->db->get(TBL_ESCORT_NEWS)->result();
	}
	function save(){
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		$ci->db->set('language_id',$this->getLanguageId());
		$ci->db->set('category_id',$this->getCategoryId());
		$ci->db->set('order',$this->getOrder());
		$ci->db->set('title',$this->getTitle());
		$ci->db->set('slug',$this->getSlug());
		$ci->db->set('news',$this->getNews());
		$ci->db->set('created_time',$this->getCreatedTime());
		$ci->db->set('status',$this->getStatus());
		$ci->db->set('site_ref',$this->getSiteRef());
		$ci->db->insert(TBL_ESCORT_NEWS);
		$id = $ci->db->insert_id();
		return $id;
	}
	function update(){
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		$ci->db->set('language_id',$this->getLanguageId());
		$ci->db->set('category_id',$this->getCategoryId());
		$ci->db->set('order',$this->getOrder());
		$ci->db->set('title',$this->getTitle());
		$ci->db->set('slug',$this->getSlug());
		$ci->db->set('news',$this->getNews());
		$ci->db->set('created_time',$this->getCreatedTime());
		$ci->db->set('status',$this->getStatus());
		$ci->db->set('site_ref',$this->getSiteRef());
		return $ci->db->where('id', $this->id)->update(TBL_ESCORT_NEWS);
	}
	function count_by(){
		echo "here";
	}
	function delete($id){
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		$ci->db->where('id',$id);
		$ci->db->delete(TBL_ESCORT_NEWS);
	}
	
	function getNewsByCategoryName($cat_name){
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		$qr = "SELECT A.*,B.*,A.id as newsid FROM ".TBL_ESCORT_NEWS." AS A INNER JOIN ".TBL_ESCORT_CATEGORY_NEWS." AS B ON A.category_id=B.id ";
		$qr .= "WHERE B.category LIKE '$cat_name' AND A.language_id=".get_language_id();
		$qr .= " AND (A.site_ref IS NULL OR A.site_ref = 0 OR A.site_ref LIKE '".SITE_REF."') ";
		$qr .=	" AND A.status LIKE 'active' ORDER BY A.order ASC";
		return $ci->db->query($qr)->result();		
	}
	
	function getArticle($slug){
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		$qr = "SELECT * FROM ".TBL_ESCORT_NEWS." WHERE slug LIKE '$slug' AND site_ref LIKE '".SITE_REF."' AND language_id=".get_language_id();
		return $ci->db->query($qr)->result();		
	}
	 
	//endclass
}